package com.example.demo.controller;


import com.example.demo.entity.Banner;
import com.example.demo.service.IBannerService;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PassToken;
import com.example.demo.utils.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * bannerController
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/system/banner")
public class BannerController
{
    @Autowired
    private IBannerService bannerService;

    /**
     * 查询banner列表
     */
    @PassToken
    @GetMapping("/list")
    public ServerResponse list(Banner banner, @RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "3") int pageSize)
    {
        //startPage();
        PageResult pageResult = bannerService.selectBannerList(banner,pageNum,pageSize);
        return ServerResponse.createBySuccess(200,pageResult,"查询成功");
    }


//    @GetMapping("banners")
//    public ServerResponse banners(Banner banner){
//        List<Banner> banners = bannerService.selectBanners(banner);
//        return ServerResponse.createBySuccess(200,banners,"查询成功");
//    }
    /**
     * 导出banner列表
     */
//    @PreAuthorize("@ss.hasPermi('system:banner:export')")
//   / @Log(title = "banner", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Banner banner)
//    {
//        List<Banner> list = bannerService.selectBannerList(banner);
//        ExcelUtil<Banner> util = new ExcelUtil<Banner>(Banner.class);
//        util.exportExcel(response, list, "banner数据");
//    }

    /**
     * 获取banner详细信息
     */

    @GetMapping(value = "/{id}")
    public ServerResponse getInfo(@PathVariable("id") Long id)
    {

        return ServerResponse.createBySuccess(200,bannerService.selectBannerById(id),"");
    }

    /**
     * 新增banner
     */

    @PostMapping
    public ServerResponse<? extends Object> add(@RequestBody Banner banner)
    {
        int i = bannerService.insertBanner(banner);
        if(i>0){
            return ServerResponse.createBySuccess(200," ","添加成功");
        }
        return ServerResponse.createByFail(500,"添加失败");
    };

    /**
     * 修改banner
     */


    @PutMapping
    public ServerResponse edit(@RequestBody Banner banner)
    {
        int i =bannerService.updateBanner(banner);

        if(i>0){
            return ServerResponse.createBySuccess(200," ","更新成功");
        }
        return ServerResponse.createByFail(500,"更新失败");
    }

    /**
     * 删除banner
     */
	@DeleteMapping("/{ids}")
    public ServerResponse remove(@PathVariable Long[] ids)
    {
        int i=bannerService.deleteBannerByIds(ids);
        if(i>0){
            return ServerResponse.createBySuccess(200," ","删除成功");
        }
        return ServerResponse.createByFail(500,"删除失败");
    }
}
